import { BlockEnum } from '@/components/workflow/types'
import { generateUUID } from '@/utils'
import { ALL_COMPLETION_AVAILABLE_BLOCKS } from '../../constants'
import { ListNodeType } from './types'

export const getListDefaultParams = () => {
  return {
    inputList: [
      {
        id: generateUUID(8),
        type: 'cite',
        label: '文件列表',
        variable: 'files',
        required: true,
        value: '',
      }
    ],
    outputList: [
      {
        id: generateUUID(8),
        variable: 'result', // 变量名
        value: '过滤结果', 
        type: 'Array[File]', // 变量类型
      },
      {
        id: generateUUID(8),
        variable: 'first_record', // 变量名
        value: '第一条记录', 
        type: 'File', // 变量类型
      },
      {
        id: generateUUID(8),
        variable: 'last_record', // 变量名
        value: '最后一条记录', 
        type: 'File', // 变量类型
      }
    ],
    filter: {
      enabled : false,
      logic: 'and', // and | or
      rules: [
        {
          field: '',
          operator: '',
          value: '', 
        }
      ],
    }, // 过滤条件
    takeTopN: {
      enabled: false,
      value: 1,
    }, // 限制条数
    sort: { 
      enabled: false,
      field: '',
      order: 'asc', // asc | desc   
    },
    takeN:{
      enabled: false,
      value: 1,
    }, // 获取第几条
    separator: '\n'  // 默认使用换行符作为分隔符
  }
}

export default {
  getAvailablePrevNodes() {
    const nodes = ALL_COMPLETION_AVAILABLE_BLOCKS.filter(type => type !== BlockEnum.End)
    return nodes
  },
  getAvailableNextNodes() {
    const nodes = ALL_COMPLETION_AVAILABLE_BLOCKS
    return nodes
  },
  checkValid: (payload: ListNodeType) => {
    return true
  }
}